package com.s2u2m.training.ex_programmer.liskov_substitution.good;

import com.s2u2m.training.ex_programmer.liskov_substitution.Shape;

public class GoodPractice {
    public static void main(String[] args) {
        Shape shape = new Rectangle();

        double length = 1.3;
        double width = 2.3;
        checkFormat(length);
        checkFormat(width);
        Double area = shape.area(length, width);
        System.out.println(area);

        double length1 = 1.322;
        double width1 = 2.333;
        checkFormat(length1);
        checkFormat(width1);
        area = shape.area(length1, width1);
        System.out.println(area);
    }

    private static void checkFormat(Double value) throws NumberFormatException {
        String s = Double.toString(value);
        int index = s.indexOf('.');
        int length = s.substring(index + 1).length();
        if (length > 2) {
            throw new NumberFormatException();
        }
    }
}
